#include <bits/stdc++.h>
using namespace std;
int T,n,x,t[20009],ans;
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    while(T--)
    {
        cin>>n;
        for(int i=1;i<=n;i++) cin>>x,t[x]++;
        for(int i=1;i<=2000;i++) if(t[i]>1) ans+=i*(t[i]-1);
        cout<<ans<<endl;
    }
    return 0;
}
